<?php

namespace iBrand\Component\Goods\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class SpecsValue extends Model
{
	use SoftDeletes;

	protected $guarded = ['id'];

	public function __construct(array $attributes = [])
	{
		parent::__construct($attributes);

		$prefix = config('ibrand.app.database.prefix', 'ibrand_');

		$this->setTable($prefix . 'base_specs_value');
	}

	public function spec()
	{
		return $this->belongsTo(Spec::class, 'spec_id');
	}

	public function scopeJudge($query, $name, $spec_id, $id = 0)
	{
		return $query->where('name', $name)->where('spec_id', $spec_id)->where('id', '<>', $id)->get();
	}
}